package com.emser.unc.client.view;

import com.emser.unc.client.CloudMobile;
import com.emser.unc.client.presenter.LoginPresenter;
import com.emser.unc.client.resources.GlobalResources;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.HasClickHandlers;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
import com.google.gwt.user.client.ui.HasVerticalAlignment;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.SimplePanel;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;

public class LoginView extends Composite implements LoginPresenter.Display {
	private final Button btnLogin;
	private final GlobalResources resource;
	
	public LoginView() {	
		VerticalPanel verticalPanel = new VerticalPanel();
		initWidget(verticalPanel);
		resource = GWT.create(GlobalResources.class);
		verticalPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
		verticalPanel.setStylePrimaryName("gwt-panelVerticalLogin");
		verticalPanel.setSize("100%", "100%");
		verticalPanel.setStyleName("gwt-panelVerticalLogin");
		
		FlexTable flexTable = new FlexTable();
		flexTable.setStylePrimaryName("gwt-FlexTable1");
		flexTable.setStyleName("gwt-FlexTable1");
		verticalPanel.add(flexTable);
		verticalPanel.setCellHorizontalAlignment(flexTable, HasHorizontalAlignment.ALIGN_CENTER);
		verticalPanel.setCellHeight(flexTable, "100%");
		verticalPanel.setCellWidth(flexTable, "100%");
		flexTable.setSize("780px", "300px");
		
		HorizontalPanel horizontalPanel = new HorizontalPanel();
		flexTable.setWidget(0, 0, horizontalPanel);
		horizontalPanel.setSize("90%", "100%");		
		Image image = new Image(resource.getICloud());
		horizontalPanel.add(image);
		horizontalPanel.setCellWidth(image, "50%");
		horizontalPanel.setCellHeight(image, "100%");
		horizontalPanel.setCellVerticalAlignment(image, HasVerticalAlignment.ALIGN_MIDDLE);
		image.setSize("190", "87");
		
		SimplePanel simplePanel = new SimplePanel();
		simplePanel.setStyleName("gwt-SimplePanelL");
		horizontalPanel.add(simplePanel);
		horizontalPanel.setCellHeight(simplePanel, "100%");
		horizontalPanel.setCellWidth(simplePanel, "50%");
		horizontalPanel.setCellHorizontalAlignment(simplePanel, HasHorizontalAlignment.ALIGN_RIGHT);
		horizontalPanel.setCellVerticalAlignment(simplePanel, HasVerticalAlignment.ALIGN_MIDDLE);
		simplePanel.setSize("220px", "90");
		
		Label lblNewLabel_1 = new Label("                                       "+CloudMobile.constants.getMsgWelcome());
		lblNewLabel_1.setStyleName("gwt-Label-L1");
		lblNewLabel_1.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
		lblNewLabel_1.setDirectionEstimator(false);
		simplePanel.setWidget(lblNewLabel_1);
		lblNewLabel_1.setSize("220px", "100%");
		flexTable.getCellFormatter().setHeight(0, 0, "50%");
		flexTable.getCellFormatter().setWidth(0, 0, "100%");
		
		Label lblNewLabel = new Label(CloudMobile.constants.loginMessage());
		lblNewLabel.setStyleName("gwt-LabelL");
		lblNewLabel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_LEFT);
		flexTable.setWidget(1, 0, lblNewLabel);
		lblNewLabel.setSize("90%", "30px");
		flexTable.getCellFormatter().setHeight(1, 0, "20%");
		flexTable.getCellFormatter().setWidth(1, 0, "100%");
		
		btnLogin = new Button(CloudMobile.constants.login());
		flexTable.setWidget(2, 0, btnLogin);
		btnLogin.setSize("140", "50");
		flexTable.getCellFormatter().setHeight(2, 0, "30%");
		flexTable.getCellFormatter().setWidth(2, 0, "100%");
		flexTable.getCellFormatter().setHorizontalAlignment(2, 0, HasHorizontalAlignment.ALIGN_CENTER);
		flexTable.getCellFormatter().setVerticalAlignment(2, 0, HasVerticalAlignment.ALIGN_MIDDLE);
		flexTable.getCellFormatter().setVerticalAlignment(1, 0, HasVerticalAlignment.ALIGN_MIDDLE);
		flexTable.getCellFormatter().setHorizontalAlignment(1, 0, HasHorizontalAlignment.ALIGN_LEFT);
		
		SimplePanel simplePanel_1 = new SimplePanel();
		verticalPanel.add(simplePanel_1);
		verticalPanel.setCellHorizontalAlignment(simplePanel_1, HasHorizontalAlignment.ALIGN_CENTER);
		simplePanel_1.setSize("100%", "30px");
		
		SimplePanel simplePanel_2 = new SimplePanel();
		verticalPanel.add(simplePanel_2);
		verticalPanel.setCellHorizontalAlignment(simplePanel_2, HasHorizontalAlignment.ALIGN_CENTER);
		simplePanel_2.setSize("780px", "100%");
		verticalPanel.setCellHeight(simplePanel_2, "40px");
		verticalPanel.setCellWidth(simplePanel_2, "780px");
		
		Label lblNewLabel_2 = new Label(CloudMobile.constants.getMsgInfo());
		lblNewLabel_2.setStyleName("gwt-LabelInfoPanelL");
		lblNewLabel_2.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_LEFT);
		simplePanel_2.setWidget(lblNewLabel_2);
		lblNewLabel_2.setSize("720px", "100%");
		
		setStyleName("body");
		setStylePrimaryName("body");
	}

	@Override
	public HasClickHandlers getLoginButton() {
		return btnLogin;
	}
	
	@Override
	public Widget asWidget() {
	    return this;
	}	
	
}
